/*******************************************************************/
/* @ All Rights Reserved Copyright (C) 2014 broada,Co.,Ltd.        */
/*                                                                 */
/*  NAME      = __ibmmq_submd_analysis.c                           */
/*  NOTE      =                                                    */
/*  DATE      = 2016/04/08 by jikw                                 */
/*******************************************************************/
#include <CUnit/Basic.h>
#include <stdlib.h>

#include "frcomm.h"
#include "frct_comm.h"
#include "../../../src/module/ibmmq/config.h"
#include "../test_ibmmq_comm.h"
#include <apmtest_comm.h>
#include <frreport_opt.h>
#include <ibmmq/cnaps2.h>
#include <ibmmq/ibmmq_core.h>

static int __suite_init(void)
{
	return 0;
}

static int __suite_cleanup(void)
{
	return 0;
}

static void read_file(char *p_filename, char **p_out, int *p_i_len)
{
    FILE *p_file = NULL;
    //struct stat buf;
    char *p_data = NULL;
    int i_len = 0;

    p_file = fopen(p_filename, "r");
    fseek(p_file, 0, SEEK_END);
    i_len = ftell(p_file);
    rewind(p_file);

    p_data = (char *)frmalloc(i_len + 1);
    memset(p_data, 0x00, i_len + 1);
    fread(p_data, 1, i_len, p_file);
    fclose(p_file);

    *p_out = p_data;
    *p_i_len = i_len;

    return;
}

extern int __ibmmq_md_analysis(L7session_ibmmq_private *p_st_private
                                , Frreport_body_data *p_st_body_data
                                , uint32_t u32_byte_order
                                , Frbyte_Packet *p_st_data
                                , unsigned int *p_ui_data_len
                                , short *p_s_ccsid
                                , int i_req_resp
                                , char *p_format);

extern int __ibmmq_pmo_analysis(Frbyte_Packet *p_st_data
                                 , unsigned int *p_ui_data_len
                                 , uint32_t u32_byte_order);

extern int __ibmmq_submd_analysis(L7session_ibmmq_private *p_st_private
                                   , Frreport_body_data *p_st_body_data
                                   , Frbyte_Packet *p_st_data
                                   , unsigned int ui_left_len
                                   , char *p_report_pre
                                   , unsigned int *p_ui_offset
                                   , short *p_s_ccsid);

static void case1(void)
{
    int i_ret = FR_SUCC;
    L7session_ibmmq_private *p_st_private = NULL;
    Frreport_body_data *p_st_body_data = NULL;
    Frbyte_Packet *p_st_data = NULL;
    unsigned int ui_left_len = 0;
    char *p_report_pre = NULL;
    unsigned int ui_offset = 0;
    short s_ccsid = 0;

    i_ret = __ibmmq_submd_analysis(p_st_private, p_st_body_data, p_st_data, ui_left_len, p_report_pre, &ui_offset, &s_ccsid);

    CU_ASSERT_EQUAL(i_ret, FR_FAIL);

    return;
}



static void case2(void)
{
    char *p_data = NULL;
    int i_len = 0;
    int i_md_idx = 0;
    uint32_t u32_byte_order = 1;
    int i_req_resp = 0;

    int i_ret = FR_SUCC;
    L7session_ibmmq_private *p_st_private = NULL;
    Frreport_body_data *p_st_body_data = NULL;
    Frbyte_Packet *p_st_data = NULL;
    unsigned int ui_left_len = 0;
    //char *p_report_pre = NULL;
    unsigned int ui_offset = 0;
    short s_ccsid = 0;
    L7Session_ibmmq *p_st_L7_session = NULL;

    char arr_format[16];
    memset(arr_format, 0x00, 16); 

    p_st_private = (L7session_ibmmq_private *)frmalloc(sizeof(L7session_ibmmq_private));
    memset(p_st_private, 0x00, sizeof(L7session_ibmmq_private));

    p_st_L7_session = (L7Session_ibmmq *)frmalloc(sizeof(L7Session_ibmmq));
    memset(p_st_L7_session, 0x00, sizeof(L7Session_ibmmq));
    p_st_private->p_st_l7_session = p_st_L7_session;
    
    p_st_body_data = (Frreport_body_data *)frmalloc(sizeof(Frreport_body_data));
    memset(p_st_body_data, 0x00, sizeof(Frreport_body_data));
    p_st_body_data->em_type = FRREPORT_TYPE_L7DATA;

    read_file((char *)"__ibmmq_submd_analysis2.pcap", &p_data, &i_len);

    p_st_data = bytebuff_creat();
    bytebuff_add(p_st_data, p_data+36, i_len-36);
    ui_left_len = i_len-36;

    bytebuff_memstr(p_st_data, 0, ui_left_len, "MD", 2, &i_md_idx);
    bytebuff_skip(p_st_data, i_md_idx);
    ui_left_len -= i_md_idx;

    __ibmmq_md_analysis(p_st_private, p_st_body_data, u32_byte_order, p_st_data, &ui_left_len, &s_ccsid ,i_req_resp, arr_format);
    __ibmmq_pmo_analysis(p_st_data, &ui_left_len, u32_byte_order);
    bytebuff_skip(p_st_data, 4);
    ui_left_len -= 4;

    i_ret = __ibmmq_submd_analysis(p_st_private, p_st_body_data, p_st_data, ui_left_len, arr_format, &ui_offset, &s_ccsid);

    CU_ASSERT_EQUAL(i_ret, FR_FAIL);

    frfree(p_data);
    bytebuff_free(&p_st_data);
    frfree(p_st_private->p_st_l7_session->p_queue);
    frfree(p_st_L7_session);
    frfree(p_st_private);
    frreport_body_free(&p_st_body_data);

    return;
}

static void case3(void)
{
    char *p_data = NULL;
    int i_len = 0;
    int i_md_idx = 0;
    uint32_t u32_byte_order = 1;
    int i_req_resp = 0;

    int i_ret = FR_SUCC;
    L7session_ibmmq_private *p_st_private = NULL;
    Frreport_body_data *p_st_body_data = NULL;
    Frbyte_Packet *p_st_data = NULL;
    unsigned int ui_left_len = 0;
    //char *p_report_pre = NULL;
    unsigned int ui_offset = 0;
    short s_ccsid = 0;
    L7Session_ibmmq *p_st_L7_session = NULL;

    char arr_format[16];
    memset(arr_format, 0x00, 16); 

    p_st_private = (L7session_ibmmq_private *)frmalloc(sizeof(L7session_ibmmq_private));
    memset(p_st_private, 0x00, sizeof(L7session_ibmmq_private));

    p_st_L7_session = (L7Session_ibmmq *)frmalloc(sizeof(L7Session_ibmmq));
    memset(p_st_L7_session, 0x00, sizeof(L7Session_ibmmq));
    p_st_private->p_st_l7_session = p_st_L7_session;
    
    p_st_body_data = (Frreport_body_data *)frmalloc(sizeof(Frreport_body_data));
    memset(p_st_body_data, 0x00, sizeof(Frreport_body_data));
    p_st_body_data->em_type = FRREPORT_TYPE_L7DATA;

    read_file((char *)"__ibmmq_submd_analysis3.pcap", &p_data, &i_len);

    p_st_data = bytebuff_creat();
    bytebuff_add(p_st_data, p_data+36, i_len-36);
    ui_left_len = i_len-36;

    bytebuff_memstr(p_st_data, 0, ui_left_len, "MD", 2, &i_md_idx);
    bytebuff_skip(p_st_data, i_md_idx);
    ui_left_len -= i_md_idx;

    __ibmmq_md_analysis(p_st_private, p_st_body_data, u32_byte_order, p_st_data, &ui_left_len, &s_ccsid ,i_req_resp, arr_format);
    __ibmmq_pmo_analysis(p_st_data, &ui_left_len, u32_byte_order);
    bytebuff_skip(p_st_data, 4);
    ui_left_len -= 4;

    i_ret = __ibmmq_submd_analysis(p_st_private, p_st_body_data, p_st_data, ui_left_len, arr_format, &ui_offset, &s_ccsid);

    CU_ASSERT_EQUAL(i_ret, FR_FAIL);

    frfree(p_data);
    bytebuff_free(&p_st_data);
    frfree(p_st_private->p_st_l7_session->p_queue);
    frfree(p_st_L7_session);
    frfree(p_st_private);
    frreport_body_free(&p_st_body_data);

    return;
}

static void case4(void)
{
    char *p_data = NULL;
    int i_len = 0;
    int i_md_idx = 0;
    uint32_t u32_byte_order = 1;
    int i_req_resp = 0;
    L7_head_ibmmq *p_st_head = NULL;

    int i_ret = FR_SUCC;
    L7session_ibmmq_private *p_st_private = NULL;
    Frreport_body_data *p_st_body_data = NULL;
    Frbyte_Packet *p_st_data = NULL;
    unsigned int ui_left_len = 0;
    //char *p_report_pre = NULL;
    unsigned int ui_offset = 0;
    short s_ccsid = 0;
    L7Session_ibmmq *p_st_L7_session = NULL;

    char arr_format[16];
    memset(arr_format, 0x00, 16);

    p_st_head = (L7_head_ibmmq *)frmalloc(sizeof(L7_head_ibmmq));
    memset(p_st_head, 0x00, sizeof(L7_head_ibmmq));

    p_st_private = (L7session_ibmmq_private *)frmalloc(sizeof(L7session_ibmmq_private));
    memset(p_st_private, 0x00, sizeof(L7session_ibmmq_private));
    p_st_private->p_st_head = p_st_head;

    p_st_L7_session = (L7Session_ibmmq *)frmalloc(sizeof(L7Session_ibmmq));
    memset(p_st_L7_session, 0x00, sizeof(L7Session_ibmmq));
    p_st_private->p_st_l7_session = p_st_L7_session;
    
    p_st_body_data = (Frreport_body_data *)frmalloc(sizeof(Frreport_body_data));
    memset(p_st_body_data, 0x00, sizeof(Frreport_body_data));
    p_st_body_data->em_type = FRREPORT_TYPE_L7DATA;

    read_file((char *)"__ibmmq_submd_analysis4.pcap", &p_data, &i_len);

    p_st_data = bytebuff_creat();
    bytebuff_add(p_st_data, p_data+36, i_len-36);
    ui_left_len = i_len-36;

    bytebuff_memstr(p_st_data, 0, ui_left_len, "MD", 2, &i_md_idx);
    bytebuff_skip(p_st_data, i_md_idx);
    ui_left_len -= i_md_idx;

    __ibmmq_md_analysis(p_st_private, p_st_body_data, u32_byte_order, p_st_data, &ui_left_len, &s_ccsid ,i_req_resp, arr_format);
    __ibmmq_pmo_analysis(p_st_data, &ui_left_len, u32_byte_order);
    bytebuff_skip(p_st_data, 4);
    ui_left_len -= 4;

    i_ret = __ibmmq_submd_analysis(p_st_private, p_st_body_data, p_st_data, ui_left_len, arr_format, &ui_offset, &s_ccsid);

    CU_ASSERT_EQUAL(i_ret, FR_SUCC);
    CU_ASSERT_EQUAL(ui_offset, 140);
    //CU_ASSERT_EQUAL(s_ccsid, 1208);

    frfree(p_data);
    bytebuff_free(&p_st_data);
    frfree(p_st_head);
    frfree(p_st_private->p_st_l7_session->p_queue);
    frfree(p_st_L7_session);
    frfree(p_st_private);
    frreport_body_free(&p_st_body_data);

    return;
}

static void case5(void)
{
    char *p_data = NULL;
    int i_len = 0;
    int i_md_idx = 0;
    uint32_t u32_byte_order = 1;
    int i_req_resp = 0;

    int i_ret = FR_SUCC;
    L7session_ibmmq_private *p_st_private = NULL;
    Frreport_body_data *p_st_body_data = NULL;
    Frbyte_Packet *p_st_data = NULL;
    unsigned int ui_left_len = 0;
    //char *p_report_pre = NULL;
    unsigned int ui_offset = 0;
    short s_ccsid = 0;
    L7Session_ibmmq *p_st_L7_session = NULL;

    char arr_format[16];
    memset(arr_format, 0x00, 16);

    p_st_private = (L7session_ibmmq_private *)frmalloc(sizeof(L7session_ibmmq_private));
    memset(p_st_private, 0x00, sizeof(L7session_ibmmq_private));

    p_st_L7_session = (L7Session_ibmmq *)frmalloc(sizeof(L7Session_ibmmq));
    memset(p_st_L7_session, 0x00, sizeof(L7Session_ibmmq));
    p_st_private->p_st_l7_session = p_st_L7_session;
    
    p_st_body_data = (Frreport_body_data *)frmalloc(sizeof(Frreport_body_data));
    memset(p_st_body_data, 0x00, sizeof(Frreport_body_data));
    p_st_body_data->em_type = FRREPORT_TYPE_L7DATA;

    read_file((char *)"__ibmmq_submd_analysis5.pcap", &p_data, &i_len);

    p_st_data = bytebuff_creat();
    bytebuff_add(p_st_data, p_data+36, i_len-36);
    ui_left_len = i_len-36;

    bytebuff_memstr(p_st_data, 0, ui_left_len, "MD", 2, &i_md_idx);
    bytebuff_skip(p_st_data, i_md_idx);
    ui_left_len -= i_md_idx;

    __ibmmq_md_analysis(p_st_private, p_st_body_data, u32_byte_order, p_st_data, &ui_left_len, &s_ccsid ,i_req_resp, arr_format);
    __ibmmq_pmo_analysis(p_st_data, &ui_left_len, u32_byte_order);
    bytebuff_skip(p_st_data, 4);
    ui_left_len -= 4;

    i_ret = __ibmmq_submd_analysis(p_st_private, p_st_body_data, p_st_data, ui_left_len, arr_format, &ui_offset, &s_ccsid);

    CU_ASSERT_EQUAL(i_ret, FR_FAIL);

    frfree(p_data);
    bytebuff_free(&p_st_data);
    frfree(p_st_private->p_st_l7_session->p_queue);
    frfree(p_st_L7_session);
    frfree(p_st_private);
    frreport_body_free(&p_st_body_data);

    return;
}

static void case6(void)
{
    char *p_data = NULL;
    int i_len = 0;
    int i_md_idx = 0;
    uint32_t u32_byte_order = 1;
    int i_req_resp = 0;
    L7_head_ibmmq *p_st_head = NULL;

    int i_ret = FR_SUCC;
    L7session_ibmmq_private *p_st_private = NULL;
    Frreport_body_data *p_st_body_data = NULL;
    Frbyte_Packet *p_st_data = NULL;
    unsigned int ui_left_len = 0;
    //char *p_report_pre = NULL;
    unsigned int ui_offset = 0;
    short s_ccsid = 0;
    L7Session_ibmmq *p_st_L7_session = NULL;

    char arr_format[16];
    memset(arr_format, 0x00, 16);

    p_st_head = (L7_head_ibmmq *)frmalloc(sizeof(L7_head_ibmmq));
    memset(p_st_head, 0x00, sizeof(L7_head_ibmmq));

    p_st_private = (L7session_ibmmq_private *)frmalloc(sizeof(L7session_ibmmq_private));
    memset(p_st_private, 0x00, sizeof(L7session_ibmmq_private));
    p_st_private->p_st_head = p_st_head;

    p_st_L7_session = (L7Session_ibmmq *)frmalloc(sizeof(L7Session_ibmmq));
    memset(p_st_L7_session, 0x00, sizeof(L7Session_ibmmq));
    p_st_private->p_st_l7_session = p_st_L7_session;
    
    p_st_body_data = (Frreport_body_data *)frmalloc(sizeof(Frreport_body_data));
    memset(p_st_body_data, 0x00, sizeof(Frreport_body_data));
    p_st_body_data->em_type = FRREPORT_TYPE_L7DATA;

    read_file((char *)"__ibmmq_submd_analysis6.pcap", &p_data, &i_len);

    p_st_data = bytebuff_creat();
    bytebuff_add(p_st_data, p_data+36, i_len-36);
    ui_left_len = i_len-36;

    bytebuff_memstr(p_st_data, 0, ui_left_len, "MD", 2, &i_md_idx);
    bytebuff_skip(p_st_data, i_md_idx);
    ui_left_len -= i_md_idx;

    __ibmmq_md_analysis(p_st_private, p_st_body_data, u32_byte_order, p_st_data, &ui_left_len, &s_ccsid ,i_req_resp, arr_format);
    __ibmmq_pmo_analysis(p_st_data, &ui_left_len, u32_byte_order);
    bytebuff_skip(p_st_data, 4);
    ui_left_len -= 4;

    i_ret = __ibmmq_submd_analysis(p_st_private, p_st_body_data, p_st_data, ui_left_len, arr_format, &ui_offset, &s_ccsid);

    CU_ASSERT_EQUAL(i_ret, FR_SUCC);
    CU_ASSERT_EQUAL(ui_offset, 312);

    frfree(p_data);
    bytebuff_free(&p_st_data);
    frfree(p_st_head);
    frfree(p_st_private->p_st_l7_session->p_queue);
    frfree(p_st_L7_session);
    frfree(p_st_private);
    frreport_body_free(&p_st_body_data);

    return;
}

static void case7(void)
{
    char *p_data = NULL;
    int i_len = 0;
    int i_md_idx = 0;
    uint32_t u32_byte_order = 1;
    int i_req_resp = 0;
    L7_head_ibmmq *p_st_head = NULL;

    int i_ret = FR_SUCC;
    L7session_ibmmq_private *p_st_private = NULL;
    Frreport_body_data *p_st_body_data = NULL;
    Frbyte_Packet *p_st_data = NULL;
    unsigned int ui_left_len = 0;
    //char *p_report_pre = NULL;
    unsigned int ui_offset = 0;
    short s_ccsid = 0;
    L7Session_ibmmq *p_st_L7_session = NULL;

    char arr_format[16];
    memset(arr_format, 0x00, 16);

    p_st_head = (L7_head_ibmmq *)frmalloc(sizeof(L7_head_ibmmq));
    memset(p_st_head, 0x00, sizeof(L7_head_ibmmq));

    p_st_private = (L7session_ibmmq_private *)frmalloc(sizeof(L7session_ibmmq_private));
    memset(p_st_private, 0x00, sizeof(L7session_ibmmq_private));
    p_st_private->p_st_head = p_st_head;

    p_st_L7_session = (L7Session_ibmmq *)frmalloc(sizeof(L7Session_ibmmq));
    memset(p_st_L7_session, 0x00, sizeof(L7Session_ibmmq));
    p_st_private->p_st_l7_session = p_st_L7_session;
    
    p_st_body_data = (Frreport_body_data *)frmalloc(sizeof(Frreport_body_data));
    memset(p_st_body_data, 0x00, sizeof(Frreport_body_data));
    p_st_body_data->em_type = FRREPORT_TYPE_L7DATA;

    read_file((char *)"__ibmmq_submd_analysis7.pcap", &p_data, &i_len);

    p_st_data = bytebuff_creat();
    bytebuff_add(p_st_data, p_data+36, i_len-36);
    ui_left_len = i_len-36;

    bytebuff_memstr(p_st_data, 0, ui_left_len, "MD", 2, &i_md_idx);
    bytebuff_skip(p_st_data, i_md_idx);
    ui_left_len -= i_md_idx;

    __ibmmq_md_analysis(p_st_private, p_st_body_data, u32_byte_order, p_st_data, &ui_left_len, &s_ccsid ,i_req_resp, arr_format);
    __ibmmq_pmo_analysis(p_st_data, &ui_left_len, u32_byte_order);
    bytebuff_skip(p_st_data, 4);
    ui_left_len -= 4;

    i_ret = __ibmmq_submd_analysis(p_st_private, p_st_body_data, p_st_data, ui_left_len, arr_format, &ui_offset, &s_ccsid);

    CU_ASSERT_EQUAL(i_ret, FR_SUCC);

    frfree(p_data);
    bytebuff_free(&p_st_data);
    frfree(p_st_head);
    frfree(p_st_private->p_st_l7_session->p_queue);
    frfree(p_st_L7_session);
    frfree(p_st_private);
    frreport_body_free(&p_st_body_data);

    return;
}

static void case8(void)
{
    char *p_data = NULL;
    int i_len = 0;
    int i_md_idx = 0;
    uint32_t u32_byte_order = 1;
    int i_req_resp = 0;
    L7_head_ibmmq *p_st_head = NULL;

    int i_ret = FR_SUCC;
    L7session_ibmmq_private *p_st_private = NULL;
    Frreport_body_data *p_st_body_data = NULL;
    Frbyte_Packet *p_st_data = NULL;
    unsigned int ui_left_len = 0;
    //char *p_report_pre = NULL;
    unsigned int ui_offset = 0;
    short s_ccsid = 0;
    L7Session_ibmmq *p_st_L7_session = NULL;

    char arr_format[16];
    memset(arr_format, 0x00, 16);

    p_st_head = (L7_head_ibmmq *)frmalloc(sizeof(L7_head_ibmmq));
    memset(p_st_head, 0x00, sizeof(L7_head_ibmmq));

    p_st_private = (L7session_ibmmq_private *)frmalloc(sizeof(L7session_ibmmq_private));
    memset(p_st_private, 0x00, sizeof(L7session_ibmmq_private));
    p_st_private->p_st_head = p_st_head;

    p_st_L7_session = (L7Session_ibmmq *)frmalloc(sizeof(L7Session_ibmmq));
    memset(p_st_L7_session, 0x00, sizeof(L7Session_ibmmq));
    p_st_private->p_st_l7_session = p_st_L7_session;
    
    p_st_body_data = (Frreport_body_data *)frmalloc(sizeof(Frreport_body_data));
    memset(p_st_body_data, 0x00, sizeof(Frreport_body_data));
    p_st_body_data->em_type = FRREPORT_TYPE_L7DATA;

    read_file((char *)"__ibmmq_submd_analysis8.pcap", &p_data, &i_len);

    p_st_data = bytebuff_creat();
    bytebuff_add(p_st_data, p_data+36, i_len-36);
    ui_left_len = i_len-36;

    bytebuff_memstr(p_st_data, 0, ui_left_len, "MD", 2, &i_md_idx);
    bytebuff_skip(p_st_data, i_md_idx);
    ui_left_len -= i_md_idx;

    __ibmmq_md_analysis(p_st_private, p_st_body_data, u32_byte_order, p_st_data, &ui_left_len, &s_ccsid ,i_req_resp, arr_format);
    __ibmmq_pmo_analysis(p_st_data, &ui_left_len, u32_byte_order);
    bytebuff_skip(p_st_data, 4);
    ui_left_len -= 4;

    i_ret = __ibmmq_submd_analysis(p_st_private, p_st_body_data, p_st_data, ui_left_len, arr_format, &ui_offset, &s_ccsid);

    CU_ASSERT_EQUAL(i_ret, FR_SUCC);

    frfree(p_data);
    bytebuff_free(&p_st_data);
    frfree(p_st_head);
    frfree(p_st_private->p_st_l7_session->p_queue);
    frfree(p_st_L7_session);
    frfree(p_st_private);
    frreport_body_free(&p_st_body_data);

    return;
}

static void case9(void)
{
    char *p_data = NULL;
    int i_len = 0;
    int i_md_idx = 0;
    uint32_t u32_byte_order = 1;
    int i_req_resp = 0;
    L7_head_ibmmq *p_st_head = NULL;

    int i_ret = FR_SUCC;
    L7session_ibmmq_private *p_st_private = NULL;
    Frreport_body_data *p_st_body_data = NULL;
    Frbyte_Packet *p_st_data = NULL;
    unsigned int ui_left_len = 0;
    //char *p_report_pre = NULL;
    unsigned int ui_offset = 0;
    short s_ccsid = 0;
    L7Session_ibmmq *p_st_L7_session = NULL;

    char arr_format[16];
    memset(arr_format, 0x00, 16);

    p_st_head = (L7_head_ibmmq *)frmalloc(sizeof(L7_head_ibmmq));
    memset(p_st_head, 0x00, sizeof(L7_head_ibmmq));

    p_st_private = (L7session_ibmmq_private *)frmalloc(sizeof(L7session_ibmmq_private));
    memset(p_st_private, 0x00, sizeof(L7session_ibmmq_private));
    p_st_private->p_st_head = p_st_head;

    p_st_L7_session = (L7Session_ibmmq *)frmalloc(sizeof(L7Session_ibmmq));
    memset(p_st_L7_session, 0x00, sizeof(L7Session_ibmmq));
    p_st_private->p_st_l7_session = p_st_L7_session; 
    
    p_st_body_data = (Frreport_body_data *)frmalloc(sizeof(Frreport_body_data));
    memset(p_st_body_data, 0x00, sizeof(Frreport_body_data));
    p_st_body_data->em_type = FRREPORT_TYPE_L7DATA;

    read_file((char *)"__ibmmq_submd_analysis9.pcap", &p_data, &i_len);

    p_st_data = bytebuff_creat();
    bytebuff_add(p_st_data, p_data+36, i_len-36);
    ui_left_len = i_len-36;

    bytebuff_memstr(p_st_data, 0, ui_left_len, "MD", 2, &i_md_idx);
    bytebuff_skip(p_st_data, i_md_idx);
    ui_left_len -= i_md_idx;

    __ibmmq_md_analysis(p_st_private, p_st_body_data, u32_byte_order, p_st_data, &ui_left_len, &s_ccsid ,i_req_resp, arr_format);
    __ibmmq_pmo_analysis(p_st_data, &ui_left_len, u32_byte_order);
    bytebuff_skip(p_st_data, 4);
    ui_left_len -= 4;

    i_ret = __ibmmq_submd_analysis(p_st_private, p_st_body_data, p_st_data, ui_left_len, arr_format, &ui_offset, &s_ccsid);

    CU_ASSERT_EQUAL(i_ret, FR_SUCC);
    CU_ASSERT_EQUAL(ui_offset, 312);

    frfree(p_data);
    bytebuff_free(&p_st_data);
    frfree(p_st_head);
    frfree(p_st_private->p_st_l7_session->p_queue);
    frfree(p_st_L7_session);
    frfree(p_st_private);
    frreport_body_free(&p_st_body_data);

    return;
}

static void case10(void)
{
    char *p_data = NULL;
    int i_len = 0;
    int i_md_idx = 0;
    uint32_t u32_byte_order = 1;
    int i_req_resp = 0;
    L7_head_ibmmq *p_st_head = NULL;

    int i_ret = FR_SUCC;
    L7session_ibmmq_private *p_st_private = NULL;
    Frreport_body_data *p_st_body_data = NULL;
    Frbyte_Packet *p_st_data = NULL;
    unsigned int ui_left_len = 0;
    //char *p_report_pre = NULL;
    unsigned int ui_offset = 0;
    short s_ccsid = 0;
    L7Session_ibmmq *p_st_L7_session = NULL;

    char arr_format[16];
    memset(arr_format, 0x00, 16);

    p_st_head = (L7_head_ibmmq *)frmalloc(sizeof(L7_head_ibmmq));
    memset(p_st_head, 0x00, sizeof(L7_head_ibmmq));

    p_st_private = (L7session_ibmmq_private *)frmalloc(sizeof(L7session_ibmmq_private));
    memset(p_st_private, 0x00, sizeof(L7session_ibmmq_private));
    p_st_private->p_st_head = p_st_head;
 
    p_st_L7_session = (L7Session_ibmmq *)frmalloc(sizeof(L7Session_ibmmq));
    memset(p_st_L7_session, 0x00, sizeof(L7Session_ibmmq));
    p_st_private->p_st_l7_session = p_st_L7_session; 
    
    p_st_body_data = (Frreport_body_data *)frmalloc(sizeof(Frreport_body_data));
    memset(p_st_body_data, 0x00, sizeof(Frreport_body_data));
    p_st_body_data->em_type = FRREPORT_TYPE_L7DATA;

    read_file((char *)"__ibmmq_submd_analysis10.pcap", &p_data, &i_len);

    p_st_data = bytebuff_creat();
    bytebuff_add(p_st_data, p_data+36, i_len-36);
    ui_left_len = i_len-36;

    bytebuff_memstr(p_st_data, 0, ui_left_len, "MD", 2, &i_md_idx);
    bytebuff_skip(p_st_data, i_md_idx);
    ui_left_len -= i_md_idx;

    __ibmmq_md_analysis(p_st_private, p_st_body_data, u32_byte_order, p_st_data, &ui_left_len, &s_ccsid ,i_req_resp, arr_format);
    __ibmmq_pmo_analysis(p_st_data, &ui_left_len, u32_byte_order);
    bytebuff_skip(p_st_data, 4);
    ui_left_len -= 4;

    i_ret = __ibmmq_submd_analysis(p_st_private, p_st_body_data, p_st_data, ui_left_len, arr_format, &ui_offset, &s_ccsid);

    CU_ASSERT_EQUAL(i_ret, FR_SUCC);
    CU_ASSERT_EQUAL(ui_offset, 312);

    frfree(p_data);
    bytebuff_free(&p_st_data);
    frfree(p_st_head);
    frfree(p_st_private->p_st_l7_session->p_queue);
    frfree(p_st_L7_session);
    frfree(p_st_private);
    frreport_body_free(&p_st_body_data);

    return;
}

static void case11(void)
{
    char *p_data = NULL;
    int i_len = 0;
    int i_md_idx = 0;
    uint32_t u32_byte_order = 1;
    int i_req_resp = 0;
    L7_head_ibmmq *p_st_head = NULL;

    int i_ret = FR_SUCC;
    L7session_ibmmq_private *p_st_private = NULL;
    Frreport_body_data *p_st_body_data = NULL;
    Frbyte_Packet *p_st_data = NULL;
    unsigned int ui_left_len = 0;
    //char *p_report_pre = NULL;
    unsigned int ui_offset = 0;
    short s_ccsid = 0;
    L7Session_ibmmq *p_st_L7_session = NULL;

    char arr_format[16];
    memset(arr_format, 0x00, 16);

    p_st_head = (L7_head_ibmmq *)frmalloc(sizeof(L7_head_ibmmq));
    memset(p_st_head, 0x00, sizeof(L7_head_ibmmq));

    p_st_private = (L7session_ibmmq_private *)frmalloc(sizeof(L7session_ibmmq_private));
    memset(p_st_private, 0x00, sizeof(L7session_ibmmq_private));
    p_st_private->p_st_head = p_st_head;
    
    p_st_L7_session = (L7Session_ibmmq *)frmalloc(sizeof(L7Session_ibmmq));
    memset(p_st_L7_session, 0x00, sizeof(L7Session_ibmmq));
    p_st_private->p_st_l7_session = p_st_L7_session;
    
    p_st_body_data = (Frreport_body_data *)frmalloc(sizeof(Frreport_body_data));
    memset(p_st_body_data, 0x00, sizeof(Frreport_body_data));
    p_st_body_data->em_type = FRREPORT_TYPE_L7DATA;

    read_file((char *)"__ibmmq_submd_analysis11.pcap", &p_data, &i_len);

    p_st_data = bytebuff_creat();
    bytebuff_add(p_st_data, p_data+36, i_len-36);
    ui_left_len = i_len-36;

    bytebuff_memstr(p_st_data, 0, ui_left_len, "MD", 2, &i_md_idx);
    bytebuff_skip(p_st_data, i_md_idx);
    ui_left_len -= i_md_idx;

    __ibmmq_md_analysis(p_st_private, p_st_body_data, u32_byte_order, p_st_data, &ui_left_len, &s_ccsid ,i_req_resp, arr_format);
    __ibmmq_pmo_analysis(p_st_data, &ui_left_len, u32_byte_order);
    bytebuff_skip(p_st_data, 4);
    ui_left_len -= 4;

    i_ret = __ibmmq_submd_analysis(p_st_private, p_st_body_data, p_st_data, ui_left_len, arr_format, &ui_offset, &s_ccsid);

    CU_ASSERT_EQUAL(i_ret, FR_SUCC);

    frfree(p_data);
    bytebuff_free(&p_st_data);
    frfree(p_st_head);
    frfree(p_st_private->p_st_l7_session->p_queue);
    frfree(p_st_L7_session);
    frfree(p_st_private);
    frreport_body_free(&p_st_body_data);

    return;
}

static void case12(void)
{
    char *p_data = NULL;
    int i_len = 0;
    int i_md_idx = 0;
    uint32_t u32_byte_order = 1;
    int i_req_resp = 0;
    L7_head_ibmmq *p_st_head = NULL;

    int i_ret = FR_SUCC;
    L7session_ibmmq_private *p_st_private = NULL;
    Frreport_body_data *p_st_body_data = NULL;
    Frbyte_Packet *p_st_data = NULL;
    unsigned int ui_left_len = 0;
    //char *p_report_pre = NULL;
    unsigned int ui_offset = 0;
    short s_ccsid = 0;
    L7Session_ibmmq *p_st_L7_session = NULL;

    char arr_format[16];
    memset(arr_format, 0x00, 16);

    p_st_head = (L7_head_ibmmq *)frmalloc(sizeof(L7_head_ibmmq));
    memset(p_st_head, 0x00, sizeof(L7_head_ibmmq));

    p_st_private = (L7session_ibmmq_private *)frmalloc(sizeof(L7session_ibmmq_private));
    memset(p_st_private, 0x00, sizeof(L7session_ibmmq_private));
    p_st_private->p_st_head = p_st_head;
    
    p_st_L7_session = (L7Session_ibmmq *)frmalloc(sizeof(L7Session_ibmmq));
    memset(p_st_L7_session, 0x00, sizeof(L7Session_ibmmq));
    p_st_private->p_st_l7_session = p_st_L7_session;
    
    p_st_body_data = (Frreport_body_data *)frmalloc(sizeof(Frreport_body_data));
    memset(p_st_body_data, 0x00, sizeof(Frreport_body_data));
    p_st_body_data->em_type = FRREPORT_TYPE_L7DATA;

    read_file((char *)"__ibmmq_submd_analysis12.pcap", &p_data, &i_len);

    p_st_data = bytebuff_creat();
    bytebuff_add(p_st_data, p_data+36, i_len-36);
    ui_left_len = i_len-36;

    bytebuff_memstr(p_st_data, 0, ui_left_len, "MD", 2, &i_md_idx);
    bytebuff_skip(p_st_data, i_md_idx);
    ui_left_len -= i_md_idx;

    __ibmmq_md_analysis(p_st_private, p_st_body_data, u32_byte_order, p_st_data, &ui_left_len, &s_ccsid ,i_req_resp, arr_format);
    __ibmmq_pmo_analysis(p_st_data, &ui_left_len, u32_byte_order);
    bytebuff_skip(p_st_data, 4);
    ui_left_len -= 4;

    i_ret = __ibmmq_submd_analysis(p_st_private, p_st_body_data, p_st_data, ui_left_len, arr_format, &ui_offset, &s_ccsid);

    CU_ASSERT_EQUAL(i_ret, FR_SUCC);
    CU_ASSERT_EQUAL(ui_offset, 216);
    CU_ASSERT_EQUAL(s_ccsid, 1208);

    frfree(p_data);
    bytebuff_free(&p_st_data);
    frfree(p_st_head);
    frfree(p_st_private->p_st_l7_session->p_queue);
    frfree(p_st_L7_session);
    frfree(p_st_private);
    frreport_body_free(&p_st_body_data);

    return;
}

static void case13(void)
{
    char *p_data = NULL;
    int i_len = 0;
    int i_md_idx = 0;
    uint32_t u32_byte_order = 1;
    int i_req_resp = 0;
    L7_head_ibmmq *p_st_head = NULL;

    int i_ret = FR_SUCC;
    L7session_ibmmq_private *p_st_private = NULL;
    Frreport_body_data *p_st_body_data = NULL;
    Frbyte_Packet *p_st_data = NULL;
    unsigned int ui_left_len = 0;
    //char *p_report_pre = NULL;
    unsigned int ui_offset = 0;
    short s_ccsid = 0;
    L7Session_ibmmq *p_st_L7_session = NULL;

    char arr_format[16];
    memset(arr_format, 0x00, 16);

    p_st_head = (L7_head_ibmmq *)frmalloc(sizeof(L7_head_ibmmq));
    memset(p_st_head, 0x00, sizeof(L7_head_ibmmq));

    p_st_private = (L7session_ibmmq_private *)frmalloc(sizeof(L7session_ibmmq_private));
    memset(p_st_private, 0x00, sizeof(L7session_ibmmq_private));
    p_st_private->p_st_head = p_st_head;
   
    p_st_L7_session = (L7Session_ibmmq *)frmalloc(sizeof(L7Session_ibmmq));
    memset(p_st_L7_session, 0x00, sizeof(L7Session_ibmmq));
    p_st_private->p_st_l7_session = p_st_L7_session;
    
    p_st_body_data = (Frreport_body_data *)frmalloc(sizeof(Frreport_body_data));
    memset(p_st_body_data, 0x00, sizeof(Frreport_body_data));
    p_st_body_data->em_type = FRREPORT_TYPE_L7DATA;

    read_file((char *)"__ibmmq_submd_analysis13.pcap", &p_data, &i_len);

    p_st_data = bytebuff_creat();
    bytebuff_add(p_st_data, p_data+36, i_len-36);
    ui_left_len = i_len-36;

    bytebuff_memstr(p_st_data, 0, ui_left_len, "MD", 2, &i_md_idx);
    bytebuff_skip(p_st_data, i_md_idx);
    ui_left_len -= i_md_idx;

    __ibmmq_md_analysis(p_st_private, p_st_body_data, u32_byte_order, p_st_data, &ui_left_len, &s_ccsid ,i_req_resp, arr_format);
    __ibmmq_pmo_analysis(p_st_data, &ui_left_len, u32_byte_order);
    bytebuff_skip(p_st_data, 4);
    ui_left_len -= 4;

    i_ret = __ibmmq_submd_analysis(p_st_private, p_st_body_data, p_st_data, ui_left_len, arr_format, &ui_offset, &s_ccsid);

    CU_ASSERT_EQUAL(i_ret, FR_SUCC);

    frfree(p_data);
    bytebuff_free(&p_st_data);
    frfree(p_st_head);
    frfree(p_st_private->p_st_l7_session->p_queue);
    frfree(p_st_L7_session);
    frfree(p_st_private);
    frreport_body_free(&p_st_body_data);

    return;
}

int add_suite__ibmmq_submd_analysis(void)
{
    CU_pSuite pSuite = NULL;

    if ((pSuite = CU_add_suite(MODULE_NAME" __ibmmq_submd_analysis()", __suite_init, __suite_cleanup)) == NULL)
        return FR_FAIL;

    if (CU_add_test(pSuite, "case1", case1) == NULL ||
        CU_add_test(pSuite, "case2", case2) == NULL ||
        CU_add_test(pSuite, "case3", case3) == NULL ||
        CU_add_test(pSuite, "case4", case4) == NULL ||
        CU_add_test(pSuite, "case5", case5) == NULL ||
        CU_add_test(pSuite, "case6", case6) == NULL ||
        CU_add_test(pSuite, "case7", case7) == NULL ||
        CU_add_test(pSuite, "case8", case8) == NULL ||
        CU_add_test(pSuite, "case9", case9) == NULL ||
        CU_add_test(pSuite, "case10", case10) == NULL ||
        CU_add_test(pSuite, "case11", case11) == NULL ||
        CU_add_test(pSuite, "case12", case12) == NULL ||
        CU_add_test(pSuite, "case13", case13) == NULL)
        return FR_FAIL;

    return FR_SUCC;
}
